home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / pageGui.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  3.3 KB  |  135 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // PageGui is the main TSControl through which the game is viewed.
  8. // The PageGui also contains the hud controls.
  9. //-----------------------------------------------------------------------------
  10.  
  11. function PageGui::onWake(%this)
  12. {
  13.    %this.pageNumber = 0;
  14. }
  15.  
  16. function PageGui::onSleep(%this)
  17. {
  18. }
  19.  
  20. function PageGui::pageName(%this, %index)
  21. {
  22.    if (%index $= "")
  23.    {
  24.       %index = %this.pageNumber;
  25.      echo ("PAGE: " @ %this.pageNumber);
  26.    }
  27.    return %this.thread @ "_page" @ %index;
  28. }
  29.  
  30. function PageGui::isNextPage(%this)
  31. {
  32.    for (%num = %this.pageNumber + 1; !isObject(%this.pageName(%num)); %num += 1)
  33.       if (%num > 100)
  34.          return false;
  35.    return true;
  36. }
  37.  
  38. function PageGui::isPrevPage(%this)
  39. {
  40.    for (%num = %this.pageNumber - 1; !isObject(%this.pageName(%num)); %num -= 1)
  41.       if (%num < 0)
  42.          return false;
  43.    return true;
  44. }
  45.  
  46. function PageGui::pushThread(%this, %thread)
  47. {
  48.    if (%this.thread !$= "" )
  49.       %this.threadStack = %this.thread @ " " @ %this.pageNUmber @ " " @ %this.threadStack;
  50.    %this.popPage();
  51.    %this.thread = %thread;
  52.    %this.pushPage(1);
  53.    %this.status();
  54. }
  55.  
  56. function PageGui::popThread(%this)
  57. {
  58.    if (%this.threadStack !$= "" )
  59.    {
  60.       %this.popPage();
  61.       %this.thread = firstWord(%this.threadStack);
  62.       %this.threadStack = removeWord(%this.threadStack, 0);
  63.  
  64.       %this.pageNumber = firstWord(%this.threadStack);
  65.       %this.threadStack = removeWord(%this.threadStack, 0);
  66.    }
  67.    else
  68.       %this.thread = "";
  69.    %this.status();
  70. }
  71.  
  72. function PageGui::status(%this)
  73. {
  74.    echo ("----------------------");
  75.    echo ("THREADSTACK: " @ %this.threadStack);
  76.    echo ("THREAD: " @ %this.thread);
  77.    echo ("PAGE: " @ %this.pageNumber);
  78. }
  79.  
  80. function PageGui::popPage(%this)
  81. {
  82.    echo ("POP: " @ %this.pageName());
  83.    if (%this.pageNumber > 0)
  84.       Canvas.popDialog(%this.pageName());
  85. }
  86.  
  87. function PageGui::pushPage(%this, %pageNumber)
  88. {
  89.    // Load up the new page   
  90.    %this.pageNumber = %pageNumber;
  91.    %page = %this.pageName();
  92.    Canvas.pushDialog(%page);
  93.   
  94.    // Update the arrows to reflect next/prev page availabilty
  95.    PageGuiNextPage.setVisible(%this.isNextPage());
  96.    //PageGuiPrevPage.setVisible(%this.isPrevPage());
  97.    
  98.    // Extract demo text from page object
  99.    PageGuiTitle.setText(
  100.       "<font:Arial Bold:32><color:ffffff><just:right>" @
  101.       %page.title);
  102.    %this.status();
  103. }
  104.  
  105. function PageGui::setPageNumber(%this,%pageNumber)
  106. {
  107.    // Pop off any current page...
  108.    %this.popPage();
  109.  
  110.    // Load up the new page   
  111.    %this.pushPage(%pageNumber);
  112. }
  113.  
  114. function PageGui::nextPage(%this)
  115. {
  116.    if (%this.isNextPage())
  117.       %this.setPageNumber(%this.pageNumber + 1);
  118. }
  119.  
  120. function PageGui::prevPage(%this)
  121. {
  122.    if (%this.isPrevPage())
  123.       %this.setPageNumber(%this.pageNumber - 1);
  124.    else
  125.    {
  126.       %this.popThread();
  127.       if (%this.thread !$= "")
  128.          %this.pushPage(%this.pageNumber);
  129.       else
  130.          Canvas.setContent(mainMenuGui);
  131.    }
  132. }
  133.  
  134.  
  135.